package com.community.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.community.pojo.Cart;
import com.community.pojo.Gather;
import com.community.pojo.Product;
import com.community.service.ICartService;
import com.community.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author TangHaoSong Fly ChenJie HeYuHang
 * @since 2024-05-15
 */
@Controller
@RequestMapping("/community/cart")
@CrossOrigin
public class CartController {
    @Autowired
    private ICartService iCartService;

    @Autowired
    private IProductService iProductService;

    @RequestMapping("/add")
    public String addCart(@RequestBody Cart cart){
        iCartService.addCart(cart);
        return "Cart added successfully";
    }

    @RequestMapping("/{comsumerId}")
    public List<Cart> getCartsByConsumerId(@PathVariable Long comsumerId){
        return iCartService.getCartsByConsumerId(comsumerId);
    }

    @RequestMapping
    public String updateCart(@RequestBody Cart cart){
        iCartService.updateCart(cart);
        return  "Cart updated successfully";
    }

    @RequestMapping("/{id}")
    public String deleteCart(@PathVariable Long id) {
        iCartService.deleteCart(id);
        return "Cart deleted successfully";
    }
    /**
     * 查询所有商品和购物车  不带条件
     */
    @RequestMapping("/list")
    @ResponseBody
    public List<Cart> productList() {
        return this.iCartService.selectCartProduct();
    }
}
